﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace Tizer.Web.Helper
{
    /// <summary>
    /// Языковой модуль
    /// </summary>
    public class LanguageModule : IHttpModule
    {
        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            Page page = HttpContext.Current.CurrentHandler as Page;
            if (page != null)
            {
                page.PreInit += new EventHandler(page_preInit);
            }
        }

        void page_preInit(object sender, EventArgs e)
        {
            Page page = sender as Page;
            if (page != null)
            {
                if (HttpContext.Current.Session["Culture"] != null)
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo((string)HttpContext.Current.Session["Culture"]);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo((string)HttpContext.Current.Session["Culture"]);
                }
                else
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ru-ru");
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ru-ru");
                }
            }
        }

    }
}